package com.fooddiary.model;

import java.io.Serializable;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.fooddiary.model.entity.BaseEntity;

@Entity
@Table(name = "user")
@AttributeOverrides({
	@AttributeOverride(name="enabled", column=@Column(name="enabled")),
	@AttributeOverride(name="id", column=@Column(name="id"))
})	
public class User extends BaseEntity implements Serializable{

	private static final long serialVersionUID = 2411113935762397066L;

	@Column(name = "login", unique = true, nullable = false, insertable = true, updatable = true, length = 20)
	private String login;
	
	@Column(name = "password", unique = false, nullable = false, insertable = true, updatable = true, length = 20)
	private String password;
	
	@Column(name = "first_name", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	private String firstName;
	
	@Column(name = "last_name", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	private String lastName;
	
	@Column(name = "email", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
	private String email;
	
	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "role_id")
	private Role role;
	
	@OneToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "model_id")
	private Model model;

	/**
	 * Default constructor for user
	 */
	public User() {

	}
	
	/**
	 * Constructor for user <br>
	 * @param p_role - user role; {@link IRole} <br>
	 * @param p_model - user model; {@link IModel} <br>
	 * @param p_enabled - enabled flag; {@link Short}
	 */
	public User(Role p_role, Model p_model, Short p_enabled) {
		role = p_role;
		model = p_model;
		enabled = p_enabled;
	}

	/**
	 * Returns user login <br>
	 * @return {@link String}
	 */
	public String getLogin() {
		return login;
	}

	/**
	 * Returns user password <br>
	 * @return {@link String}
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Returns user first name <br>
	 * @return {@link String}
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * Returns user last name <br>
	 * @return {@link String}
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * Returns user role <br>
	 * @return {@link Role}
	 */
	public Role getRole() {
		return  role;
	}
	
	/**
	 * Returns user model <br>
	 * @return {@link Model}
	 */
	public Model getModel() {
		return model;
	}

	/**
	 * Sets user login <br>
	 * @return {@link String}
	 */
	public void setLogin(String p_login) {
		login = p_login;
	}

	/**
	 * Sets user password <br>
	 * @return {@link String}
	 */
	public void setPassword(String p_password) {
		password = p_password;
	}

	/**
	 * Sets user first name <br>
	 * @return {@link String}
	 */
	public void setFirstName(String p_firstName) {
		firstName = p_firstName;
	}

	/**
	 * Sets user last name <br>
	 * @return {@link String}
	 */
	public void setLastName(String p_lastName) {
		lastName = p_lastName;
	}

	/**
	 * Sets user role <br>
	 * @return {@link Role}
	 */
	public void setRole(Role p_role) {
		role = p_role;
	}

	/**
	 * Sets user model <br>
	 * @return {@link Model}
	 */
	public void setModel(Model p_model) {
		model = p_model;
	}

	/**
	 * Returns email of user <br>
	 * @return {@link String};
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * Sets email for user <br>
	 * @param p_email - {@link String};
	 */
	public void setEmail(String p_email) {
		email = p_email;
	}

	
}
